﻿using System;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.SqlClient;

namespace ASPNETVN.PORTAL.Modules.POLL.Components
{
    public partial class Question
    {
        public static DataSet Select_QuestionBy_ModuleID(Guid moduleID)
        {
            string spName = "p_POLL_Answer_Select_Question_ByModuleID";
            SqlDatabase db = DatabaseFactory.CreateDatabase() as SqlDatabase;
            SqlCommand dbCommand = db.GetStoredProcCommand(spName) as SqlCommand;
            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.UniqueIdentifier, moduleID);
            return db.ExecuteDataSet(dbCommand);
        }

        public static int UpdateStatus(Guid moduleID, int id)
        {
            string spName = "p_POLL_UpdateStatusBy_QuestionID_ModuleID";
            SqlDatabase db = DatabaseFactory.CreateDatabase() as SqlDatabase;
            SqlCommand dbCommand = db.GetStoredProcCommand(spName) as SqlCommand;
            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.UniqueIdentifier, moduleID);
            db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, id);
            return db.ExecuteNonQuery(dbCommand);
        }

        public static int DeleleAnswerQuestion(int id)
        {
            string spName = "p_POLL_DeleteQuestionAnswerBy_QuestionID";
            SqlDatabase db = DatabaseFactory.CreateDatabase() as SqlDatabase;
            SqlCommand dbCommand = db.GetStoredProcCommand(spName) as SqlCommand;
            db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, id);
            return db.ExecuteNonQuery(dbCommand);
        }
    }
}
